package com.imooc.dao;

import com.imooc.domain.Girl;
import org.springframework.data.jpa.repository.Query;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 *  使用  Repository 表示这是一个持久化层
 * Created by ancy on 2017/7/23.
 */
@Repository
public class GirlDao {

    @Resource
    private JdbcTemplate  jdbcTemplate;

    /**
     *  1.定义一个sql语句
     *  2. 定义一个RomMapper
     *  3. 执行查询方法
     *
     * @return
     */

    public Girl selectByName (String name) {
        String sql = "SELECT * FROM girl WHERE name = ?";
        RowMapper<Girl> rowMapper = new BeanPropertyRowMapper<>(Girl.class);
        Girl girl = jdbcTemplate.queryForObject(sql, rowMapper,name);
        return  girl;
    }
}
